package com.liang.socket;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class ClientDemo {
    public static void main(String[] args) throws IOException {

        //创建发送的载体
        DatagramSocket ds = new DatagramSocket();

        //发送数据打包
        String str = "给老丈人的礼物";
        byte[] bytes = str.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");
        int port = 10000;
        //四个参数，发送的数据的字节数组，字节长度，发送地址，发送端口
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address, port);

        //发送数据
        ds.send(dp);
    }
}
